/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ai.gui;

import ai.*;
import ai.backbrop.BackPropBrain;
import ai.backbropPlus.BackPropPlusBrain;
import ai.convolution.ConvolutionBrain;
import ai.convolution.LayerConfig;
import ai.io.DataSource;
import ai.perceptron.SingleLayerPerceptronBrain;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

/**
 *
 * @author pjl
 */
public class AIFrame extends JFrame {

    private static Dimension dIn;
    private static Dimension dOut;

 
    static JMenuBar createMenuBar(JPanel panel) throws FileNotFoundException, IOException {



        JMenuBar menuBar = new JMenuBar();


        JMenu menu = new JMenu("Exit");

        menu.add(new JMenuItem(new AbstractAction("Exit"){

            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }

        }));
        menuBar.add(menu);



        menu = new JMenu("Transplant");


        Actions actions=new Actions(dIn,dOut);

        for(AbstractAction act:actions.actions) {
            JMenuItem item=new JMenuItem(act);
            menu.add(item);
            JButton but=new JButton(act);
            panel.add(but);
        }

        menuBar.add(menu);
        return menuBar;
    }

    private static void createAndShowGUI() throws FileNotFoundException, IOException {
        //    JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("Brain Launcher");
        JPanel content=new JPanel();
        frame.setContentPane(content);
        // We now also set the MenuBar of the Frame to our MenuBar
        JMenuBar bar=createMenuBar(content);
        frame.setJMenuBar(bar);
        frame.setSize(new Dimension(400, 600));
        frame.validate();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      //  frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException, InvocationTargetException {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        final DataSource trainSrc = new ImageLabelDataSource("train");
        dIn = trainSrc.getInDimension();
        dOut = trainSrc.getOutDimension();


        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                try {
                    createAndShowGUI();
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(AIFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(AIFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }


}